from rest_framework import serializers

from byxiaomi.models import FeedBack, Student, Teacher


# demo,测试用
class MySerializer(serializers.Serializer):
    name = serializers.CharField()
    age = serializers.IntegerField()
    salary = serializers.CharField()


# demo,测试用
class MySerializerRes(serializers.Serializer):
    code = serializers.IntegerField()
    method = serializers.CharField()
    data = serializers.DictField()

    def validated_code(self, data):
        return data

    def validated_method(self, data):
        return data


# 这个序列化器的作用是将FeedBack模型的实例转换为JSON格式的数据，以便在API中进行传输。
class FeedBackSerializer(serializers.ModelSerializer):
    class Meta:
        model = FeedBack
        # fields = ("id", "review")  # 使用部分字段
        fields = "__all__"  # 使用全部字段


class APIGetTokenSerializer(serializers.Serializer):
    username = serializers.CharField(required=True)
    password = serializers.CharField(required=True)


class ResAPIGetTokenSerializer(serializers.Serializer):
    code = serializers.IntegerField()
    msg = serializers.CharField()
    token = serializers.CharField()


#  =====================================================================


class StudentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Student
        # fields = ("id", "review")  # 使用部分字段
        fields = "__all__"  # 使用全部字段


class TeacherSerializer(serializers.ModelSerializer):
    class Meta:
        model = Teacher
        # fields = ("id", "review")  # 使用部分字段
        fields = "__all__"  # 使用全部字段
